<template>
  <div class="box">
    <el-form-item label="作战时间" prop="fightTime">
      <el-date-picker
        clearable
        v-model="exptForm.fightTime"
        type="datetimerange"
        start-placeholder="开始时间"
        end-placeholder="结束时间"
        format="YYYY-MM-DD HH:mm:ss"
        date-format="YYYY/MM/DD ddd"
        time-format="YYYY-MM-DD HH:mm:ss"
        range-separator="至"
        value-format="YYYY-MM-DD HH:mm:ss"
      />
    </el-form-item>
    <el-form-item label="阵营设置" prop="campSettings" class="camps">
      <div v-for="item in exptForm.campList" :key="item.id" class="camp">
        <div class="name" :style="{ background: item.color }">
          {{ item.name }}
        </div>
        <div class="country">
          <div class="tit">阵营国家：</div>
          <el-select
            style="width: 200px"
            clearable
            v-model="item.country"
            placeholder="请选择国家"
          >
            <el-option
              :label="item.name"
              :value="item.id"
              v-for="item in country"
              :key="item.id"
            />
          </el-select>
        </div>
      </div>
      <el-button @click="addCampDialogVisible = true">添加阵营</el-button>
    </el-form-item>
    <el-form-item label="作战要求描述" prop="requirementsDescribe">
      <el-input
        v-model="exptForm.requirementsDescribe"
        type="textarea"
        :rows="5"
      />
    </el-form-item>
    <el-dialog
      v-model="addCampDialogVisible"
      title="添加阵营"
      width="500"
      :before-close="handleClose"
      class="addcampDialog"
    >
      <div>
        <el-form
          ref="addCampFormRef"
          :model="addCampForm"
          :rules="addCampRules"
          class="demo-ruleForm1"
          status-icon
        >
          <el-form-item label="阵营名称" prop="name" :error="errorMsg1">
            <el-input
              v-model="addCampForm.name"
              @blur="checkMobile"
              :minlength="0"
              :maxlength="5"
              show-word-limit
              clearable
            />
          </el-form-item>
          <el-form-item label="阵营国家" prop="country">
            <el-select
              style="width: 200px"
              clearable
              v-model="addCampForm.country"
              placeholder="请选择国家"
            >
              <el-option
                :label="item.name"
                :value="item.id"
                v-for="item in country"
                :key="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="阵营颜色" prop="color">
            <el-color-picker
              v-model="addCampForm.color"
              show-alpha
              :predefine="predefineColors"
            />
          </el-form-item>
        </el-form>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="handleClose">取消</el-button>
          <el-button type="primary" @click="addCamp(addCampFormRef)">
            确定
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import { ref, onMounted, onUnmounted, inject } from "vue";
import { useRoute, useRouter } from "vue-router";
const props = defineProps({
  exptForm: {
    type: Object,
    default: () => {
      return {};
    },
  },

});
let emit = defineEmits([""]);

// 添加阵营
const addCampDialogVisible = ref(false);
const addCampForm = ref({});
const addCampFormRef = ref(null);
const addCampRules = {
  name: [
    { required: true, message: "请输入阵营名称", trigger: "blur" },
    { min: 1, max: 5, message: "阵营名称限制1-5个字", trigger: "blur" },
  ],
  country: [{ required: true, message: "请选择国家", trigger: "change" }],
  color: [{ required: true, message: "请选择颜色", trigger: "change" }],
};
const predefineColors = ref([
  "#ff4500",
  "#ff8c00",
  "#ffd700",
  "#90ee90",
  "#00ced1",
  "#1e90ff",
  "#c71585",
  "rgba(255, 69, 0, 0.68)",
  "rgb(255, 120, 0)",
  "hsv(51, 100, 98)",
  "hsva(120, 40, 94, 0.5)",
  "hsl(181, 100%, 37%)",
  "hsla(209, 100%, 56%, 0.73)",
  "#c7158577",
]);
// 国家
const country = [
  {
    name: "中国",
    id: "1",
  },
  {
    name: "美国",
    id: "2",
  },
  {
    name: "日本",
    id: "3",
  },
  {
    name: "意大利",
    id: "4",
  },
];
const addCamp = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      let obj = JSON.parse(JSON.stringify(addCampForm.value));
      obj.id = props.exptForm.campList.length;
      obj.entityList = [];
      obj.formationList = [];
      obj.seatList = [];
      props.exptForm.campList.push(obj);
     console.log( props.exptForm);
      handleClose();
      formEl.resetFields();
    } else {
      console.log("error submit!", fields);
    }
  });
};
const handleClose = () => {
  addCampDialogVisible.value = false;
};
// 校验阵营名称
const errorMsg1 = ref("");
const checkMobile = () => {
  errorMsg1.value = "";
};
onMounted(() => {});
</script>
<style scoped lang="scss">
.camps {
  max-height: 500px;
  overflow: hidden;
  overflow-y: auto;
  // border: 1px solid #8dd16b;
}
.camp {
  width: 100%;

  display: flex;
  margin-bottom: 10px;
  .name {
    width: 100px;
    text-align: center;
    margin-right: 15px;
  }
  .country {
    display: flex;
    .tit {
      // width: 100px;;
      margin-right: 5px;
    }
  }
}
:deep() {
  .el-input {
    .el-input__wrapper {
      background-color: #424242 !important;
      .el-input__inner {
        color: #fff;
      }
      .el-input__count-inner {
        background: transparent;
        color: #fff;
      }
    }
  }

  .el-select {
    .el-select__wrapper {
      background-color: #424242;

      .el-select__selected-item {
        color: #fff !important;
      }
      .is-transparent {
        color: #9eaba7 !important;
      }
    }
  }
  .el-form-item__label {
    color: #fff;
  }
  .addcampDialog {
    .demo-ruleForm1 {
      width: 60%;
    }
    .el-form-item {
      .el-form-item__label {
        color: #000 !important;
      }
      .el-form-item__content {
        .el-input {
          .el-input__wrapper {
            background-color: #fff !important;

            .el-input__inner {
              color: #000;
            }
            .el-input__count-inner {
              background: transparent;
              color: #000;
            }
          }
        }
        .duration {
          .el-input {
            .el-input__wrapper {
              background-color: transparent !important;
              .el-input__inner {
                color: #000;
              }
              .el-input__count-inner {
                color: #000;
              }
            }
          }
        }

        .el-select {
          .el-select__wrapper {
            background-color: #fff;

            .el-select__selected-item {
              color: #000 !important;
            }
            .is-transparent {
              color: #9eaba7 !important;
            }
          }
        }
      }
      .el-checkbox__label {
        color: #fff;
      }
    }
  }
}
</style>
